package top.anonyeast.controller;

import org.springframework.web.bind.annotation.*;
import top.anonyeast.pojo.Admission;
import top.anonyeast.service.AdmissionService;

import javax.annotation.Resource;

@RestController  //使用ResponseBody直接返回
@CrossOrigin  //前后端分离项目需要跨域
public class AdmissionController {
    @Resource(name = "admissionService")
    private AdmissionService admissionService;

    /**
     * 查询并保存
     * @param candidateNumber 考生号
     * @param studentName 姓名
     * @param searchType 考生号类型
     * @return 录取信息
     */
    @PostMapping("/searchAndSave")
    public Admission findAll(String candidateNumber, String studentName, Integer searchType) {
        Admission admission = admissionService.findAll(candidateNumber, studentName, searchType);
        if (admission != null) {
            admissionService.addToDB(admission);
        }
        admissionService.queryCount();
        return admission;
    }

    /**
     * 获取查询次数
     * @return
     */
    @GetMapping("/count")
    public int queryCount(){
        return admissionService.getQueryCount();
    }
}
